package dao.caminhoneiro;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class PostRequest {
	private String server;
	private List<NameValuePair> param;
	
	public PostRequest(String server){
	 this.server = server;	
	 param = new ArrayList<NameValuePair>();
	}
	
	public void addParam(String field, String content){
		param.add(new BasicNameValuePair(field, content));
	}
	
	public BufferedReader doPostRequest(){
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost(server);
		
	    try {
			post.setEntity(new UrlEncodedFormEntity(param));
			HttpResponse response = client.execute(post);
			return new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	    return null;
	}
	

}
